package com.team12.hotel404.controller.admin;

import com.team12.hotel404.domain.Hotel;
import com.team12.hotel404.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping(value = "/hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String list_all_hotel(Model model){
        List<Hotel> hotels= hotelService.listAllHotel();
        model.addAttribute("hotels",hotels);
        return "admin/hotel-list";
    }

    @RequestMapping(value = "/findById")
    public String find_hotel_by_id(Integer id,Model model){
        Hotel hotel = hotelService.findById(id);
        model.addAttribute("hotel",hotel);
        return "admin/hotel-update";
    }

    @RequestMapping(value = "/hotelMessage")
    public String find_hotel_message_by_id(Integer id, Model model) {
        Hotel hotel = hotelService.findById(id);
        model.addAttribute("hotel", hotel);
        return "admin/hotel-message";
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public String update(Hotel hotel){
        hotelService.updateHotelInfo(hotel);
        return "redirect:/hotel/list";
    }

    @RequestMapping(value = "/insert",method = RequestMethod.GET)
    public String insert_hotel(){
        return "admin/hotel-insert";
    }

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public String insert_hotel(Hotel hotel){
        hotelService.insertHotel(hotel);
        return "redirect:/hotel/list";
    }

    @RequestMapping(value = "/delHotel")
    public String deleteHotelById(Integer id){
        hotelService.deleteHotelById(id);
        return "redirect:/hotel/list";
    }
    @GetMapping(value="/hotelPage")
    public String hotelPage(){
        return "Page/single";
    }
}
